﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArraysAndStrings.ReverseWords
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ReverseWords("the    sky is blue"));
            Console.ReadKey();
        }
        public static string ReverseWords(string s)
        {
            string[] strs = s.Trim().Split(' ');
            Array.Reverse(strs);
            string str = string.Empty;
            for (int i = 0; i < strs.Length; i++)
            {
                if (i == strs.Length - 1)
                {
                    if (strs[i] != "")
                        str += strs[i];
                }
                else
                {
                    if (strs[i] != "")
                        str += strs[i] + ' ';
                }
            }
            return str;
        }
    }
}
